cmake_minimum_required(VERSION 2.6)
project(libkuato)

set (libkuato_VERSION_MAJOR 0)
set (libkuato_VERSION_MINOR 1)

cmake_policy(SET CMP0015 OLD)
include_directories( /usr/include/libxml2 ../core/include include )
link_directories( ../core )

option(ENABLE_LIBXML "Use libxml" ON)
option(ENABLE_SSL "Use openssl" ON)

add_library(kuato STATIC
http_chunked.c
http_client.c
http_messages.c
http_protocol.c
http_server_object.c
http_utils.c
match.c
messaging.c
method.c
ssl.c)

include(GNUInstallDirs)


message("Archive Dir:" ${CMAKE_INSTALL_FULL_LIBDIR} "Include:" ${CMAKE_INSTALL_FULL_INCLUDEDIR})
install(TARGETS kuato DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})

install(FILES
include/kuato_client.h
include/kuato_error_messages.h
include/kuato_http.h
include/kuato_http_internals.h
include/kuato_http_operations.h
include/kuato_server.h
include/kuato_types.h
include/libkuato_config.h
include/messaging.h
include/method.h
include/utils.h
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/kuato)

#install(DIRECTORY
#docs
#DESTINATION ${CMAKE_INTALL_FULL_DOCSDIR}/kuato)

add_executable(testweb main.c)

target_link_libraries(testweb kuato crcore uuid pthread z)

if(ENABLE_LIBXML)
	message( "LIBXML is Enabled" )
	add_definitions(-DENABLE_LIBXML)
	target_link_libraries(testweb xml2)	
endif(ENABLE_LIBXML)

if(ENABLE_SSL)
	message( "SSL is Enabled" )
	add_definitions(-DENABLE_SSL)
	target_link_libraries(testweb ssl crypto)
endif(ENABLE_SSL)

add_definitions( -Wall )

# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(docs ALL
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.config
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)

#TODO: Add package build